﻿

<title>铁路电子客票</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a><cite>铁路电子客票</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-railwayticket-formlist">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">发票号码</label>
                    <div class="layui-input-block">
                        <input type="text" name="invoiceNumber" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">开票日期</label>
                    <div class="layui-inline" id="ID-laydate-rangeLinked-railwayticket-issuedate">
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" id="ID-laydate-start-date-railwayticket-issuedate" name="issueDateStart" class="layui-input" placeholder="开始日期">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" id="ID-laydate-end-date-railwayticket-issuedate" name="issueDateEnd" class="layui-input" placeholder="结束日期">
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">上传时间</label>
                    <div class="layui-inline" id="ID-laydate-rangeLinked-railwayticket-uploadTime">
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" id="ID-laydate-start-date-railwayticket-list-uploadtime" name="uploadTimeStart" class="layui-input" placeholder="开始时间">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" id="ID-laydate-end-date-railwayticket-list-uploadtime" name="uploadTimeEnd" class="layui-input" placeholder="结束时间">
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">文件名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="fileName" placeholder="请输入" autocomplete="off" class="layui-input" />
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <input type="text" name="comment" placeholder="请输入" autocomplete="off" class="layui-input" />
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-queryinvoice-railwayticket-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 查询
                    </button>
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-on="railwayticketformlistclear">
                        <i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i> 刷新
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-queryinvoice-railwayticket-manage" lay-filter="LAY-queryinvoice-railwayticket-manage"></table>
            <script type="text/html" id="table-useradmin-webuser">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <!-- 这里同样支持 laytpl 语法，如： -->
                {{#  if(d.isEnabled == 'Y'){ }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="disable"><i class="layui-icon layui-icon-disabled"></i>禁用</a>
                {{#  }else{ }}
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="enable"><i class="layui-icon layui-icon-ok-circle"></i>启用</a>
                {{#  } }}
            </script>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="export">导出Excel</button>
                </div>
            </script>
            <script type="text/html" id="LAY-queryinvoice-railwayticket-billTypeTpl">
                <span>{{ d.billTypeName }}</span>
                {{# if(d.billType==1){ }}
                <span style="color:#16b777; border: 1px solid; padding: 0px 1px;">普</span>
                {{# }else if(d.billType==2){ }}
                <span style="color:#1e9fff; border: 1px solid; padding: 0px 1px;">专</span>
                {{# }else if(d.billType==3){ }}
                <span style="color: #a233c6; border: 1px solid; padding: 0px 1px;">机</span>
                {{# }else if(d.billType==4){ }}
                <span style="color: #ff5722; border: 1px solid; padding: 0px 1px;">铁</span>
                {{#  } }}
            </script>
            <script type="text/html" id="ID-table-queryinvoice-railwayticket-templet-invoiceNumber">
                <a class="layui-table-link billtong-myinvoice-table-invoicenumber">{{= d.invoiceNumber }}</a>
            </script>

        </div>
    </div>
</div>

<script>
    layui.use('railwayticket', layui.factory('railwayticket')).use(['admin', 'table', 'util'], function () {
        var $ = layui.$
            , admin = layui.admin
            , setter = layui.setter
            , view = layui.view
            , table = layui.table
            , laydate = layui.laydate
            , util = layui.util
            , form = layui.form;

        form.render(null, 'layadmin-railwayticket-formlist');

        // 获取今天的日期对象
        const today = new Date();
        // 设置今天的结束时间为23:59:59
        today.setHours(23, 59, 59, 999);

        // 获取30天前的日期对象
        const thirtyDaysAgo = new Date();
        thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
        // 设置30天前的开始时间为00:00:00
        thirtyDaysAgo.setHours(0, 0, 0, 0);

        // 将日期对象格式化为指定的字符串格式
        function formatDate(date) {
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            const seconds = String(date.getSeconds()).padStart(2, '0');
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        }

        const startDateStr = formatDate(thirtyDaysAgo);
        const endDateStr = formatDate(today);

        //上传时间
        laydate.render({
            elem: '#ID-laydate-rangeLinked-railwayticket-uploadTime',
            range: ['#ID-laydate-start-date-railwayticket-list-uploadtime', '#ID-laydate-end-date-railwayticket-list-uploadtime'],
            rangeLinked: true,
            type: 'datetime',
            value: startDateStr + ' - ' + endDateStr,
            isInitValue: true
        });

        //处理自定义事件
        util.on({
            railwayticketformlistclear: function () {
                console.log(this); // 当前触发事件的 DOM 元素

                $(':input[name=invoiceNumber]').val('');
                $('#ID-laydate-start-date-railwayticket-issuedate').val('');
                $('#ID-laydate-end-date-railwayticket-issuedate').val('');
                $('#ID-laydate-start-date-railwayticket-list-uploadtime').val(startDateStr);
                $('#ID-laydate-end-date-railwayticket-list-uploadtime').val(endDateStr);
                $(':input[name=fileName]').val('');
                $(':input[name=comment]').val('');
                form.render(null, 'layadmin-railwayticket-formlist');

                //执行重载
                table.reload('LAY-queryinvoice-railwayticket-manage', {
                    where: { uploadTimeStart: $('#ID-laydate-start-date-railwayticket-list-uploadtime').val(), uploadTimeEnd: $('#ID-laydate-end-date-railwayticket-list-uploadtime').val() }
                });
            }
        });

        // 日期范围 - 左右面板联动选择模式
        laydate.render({
            elem: '#ID-laydate-rangeLinked-railwayticket-issuedate',
            range: ['#ID-laydate-start-date-railwayticket-issuedate', '#ID-laydate-end-date-railwayticket-issuedate'],
            rangeLinked: true // 开启日期范围选择时的区间联动标注模式 ---  2.8+ 新增
        });

        //开启搜索
        form.on('submit(LAY-queryinvoice-railwayticket-search)', function (data) {
            var field = data.field;

            //执行重载
            table.reload('LAY-queryinvoice-railwayticket-manage', {
                where: field
            });
        });

        //事件
        var active = {
            batchdel: function () {
                var checkStatus = table.checkStatus('LAY-queryinvoice-railwayticket-manage')
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }

                layer.prompt({
                    formType: 1
                    , title: '敏感操作，请验证口令'
                }, function (value, index) {
                    layer.close(index);

                    layer.confirm('确定删除吗？', function (index) {

                        //执行 Ajax 后重载
                        /*
                        admin.req({
                          url: 'xxx'
                          //,……
                        });
                        */
                        table.reload('LAY-queryinvoice-railwayticket-manage');
                        layer.msg('已删除');
                    });
                });
            }
            , add: function () {
                admin.popup({
                    title: '添加用户'
                    , area: ['500px', '450px']
                    , id: 'LAY-popup-user-add'
                    , success: function (layero, index) {
                        view(this.id).render('user/user/userform').done(function () {
                            form.render(null, 'layuiadmin-form-useradmin');

                            //开启提交
                            form.on('submit(LAY-user-front-submit)', function (data) {
                                var field = data.field; //获取提交的字段

                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                $.ajax({
                                    url: setter.baseConfig.apiHost + '/api/user/add' //实际使用请改成服务端真实接口
                                    , type: 'post'
                                    , contentType: "application/json"
                                    , data: JSON.stringify(field)
                                    , beforeSend: function (xhr) {
                                        xhr.setRequestHeader("Authorization", 'Bearer ' + layui.data(setter.tableName)[setter.request.tokenName]);
                                    }
                                    , success: function (res) {
                                        if (res.errorCode != '00000') {
                                            layer.msg(res.errorMessage, {
                                                offset: '15px'
                                                , icon: 2
                                                , time: 3000
                                            });

                                            return false;
                                        }

                                        //登入成功的提示与跳转
                                        layer.msg('添加成功', {
                                            offset: '15px'
                                            , icon: 1
                                            , time: 3000
                                        });

                                        layui.table.reload('LAY-queryinvoice-railwayticket-manage'); //重载表格
                                        layer.close(index); //执行关闭
                                    }
                                });
                            });
                        });
                    }
                });
            }
        };

        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>